<template>
	<view class="product-page">
		<!-- 商品图片 -->
		<view class="product-image-container" @click="preview(sendGoodData.dbPicPath)">
			<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000">
				<swiper-item v-for="(pic,index) in sendGoodData.dbPicPath" :key="index">
					<view class="swiper-item">
					<image :src="pic.url" mode="aspectFit"></image>
					
				</view>
				</swiper-item>
			
			</swiper>
		</view>

		<!-- 商品信息 -->
		<view class="product-info">
			<view class="info-item">
				<text class="info-label">商品名称：</text>
				<text class="info-content">{{ sendGoodData.productName }}</text>
			</view>
			<view class="info-item">
				<text class="info-label">商品价格：</text>
				<text class="price-text">￥{{ sendGoodData.price }}</text>
				<text>/ {{ sendGoodData.unit }}</text>
			</view>
			<view class="info-item column">
				<text class="info-label">商品描述：</text>
				<text class="desc-text">{{ sendGoodData.description }}</text>
			</view>
		</view>

		<!-- 数量选择 -->
		<view class="card-section">
			<text class="section-title">购买数量</text>
			<view class="quantity-container">
				<button class="quantity-btn" :class="{ disabled: quantity <= 1 }" @click="decreaseQuantity">-</button>
				<text class="quantity">{{ quantity }}</text>
				<button class="quantity-btn" @click="increaseQuantity">+</button>
			</view>
		</view>

		<!-- 留言备注 -->
		<view class="card-section">
			<text class="section-title">留言备注</text>
			<textarea class="remark-input" :value="note" placeholder="请输入备注信息（50字以内）" maxlength="50" auto-height />
		</view>

		<!-- 底部操作栏 -->
		<view class="footer-bar">
			<view class="price-wrap">
				<text class="total-label">合计：</text>
				<text class="total-price">¥{{ totalPrice }}</text>
			</view>
			<!-- <button class="submit-btn" @click="order">立即下单</button> -->
		</view>
		<shopCar ref="shopcar"></shopCar>
	</view>
	
</template>

<script>

import shopCar from '../../components/shopCar.vue'
const db=uniCloud.databaseForJQL()
export default {
	components:{
		shopCar
	},
  data() {
	  
    return {
	  sender:{},
	  productId:"",
      quantity: 1,
      sendGoodData:{},
	  note:""
    };
  },
  computed: {
    totalPrice() {
      return this.quantity * this.sendGoodData.price;
    }
  },
async  onLoad(option) {

	const res=await  db.collection('sendgood').where({
		  "productId":option.id
	  }).get()

	 this.sendGoodData= res.data[0]
  },
  methods: {
    increaseQuantity() {
		this.addToCart(this.sendGoodData)
      this.quantity++;
    },
    decreaseQuantity() {
		let  item={quantity:this.quantity}
		item={...this.sendGoodData,...item}
		
      if (this.quantity > 1) {
		  this.quantity--
		  this.$refs.shopcar.changeQuantity(item,-1)
		  };
    },

	preview(pic){
	const urls=	pic.map(item=>item.url)
		uni.previewImage({
			urls:urls
		})
	},
	addToCart(product) {
	   this.$store.commit('cart/addItem', product)
	   uni.vibrateShort()
	   uni.showToast({
	     title: '已加入购物车'
	   })
	 },
  }
};
</script>

<style lang="scss" scoped>
.product-page {
	padding-bottom: 100px;
	background: #f8f8f8;
	min-height: 100vh;
}

.product-image-container {
	height: 360rpx;
	background: #fff;
	.product-image {
		width: 100%;
		height: 100%;
	}
}

.card-section {
	margin: 20rpx;
	padding: 30rpx;
	background: #fff;
	border-radius: 16rpx;
	box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.04);
}

.section-title {
	font-size: 32rpx;
	font-weight: 600;
	color: #333;
	margin-bottom: 30rpx;
	display: block;
}

/* 数量选择 */
.quantity-container {
	display: flex;
	align-items: center;
	.quantity-btn {
		width: 64rpx;
		height: 64rpx;
		line-height: 64rpx;
		border-radius: 50%;
		background: #ff6a00;
		color: #fff;
		font-size: 40rpx;
		padding: 0;
		&::after {
			border: none;
		}
		&.disabled {
			background: #eee;
			color: #999;
		}
	}
	.quantity {
		margin: 0 40rpx;
		font-size: 36rpx;
		color: #333;
		min-width: 80rpx;
		text-align: center;
	}
}

/* 商品信息 */
.product-info {
	@extend .card-section;
	.info-item {
		display: flex;
		margin-bottom: 24rpx;
		&.column {
			flex-direction: column;
		}
	}
	.info-label {
		color: #666;
		font-size: 28rpx;
		min-width: 140rpx;
	}
	.info-content {
		flex: 1;
		color: #333;
		font-size: 30rpx;
	}
	.price-text {
		color: #ff6a00;
		font-size: 36rpx;
		font-weight: bold;
	}
	.desc-text {
		color: #666;
		font-size: 26rpx;
		line-height: 1.6;
	}
}

/* 留言备注 */
.remark-input {
	width: 100%;
	min-height: 120rpx;
	padding: 20rpx;
	font-size: 28rpx;
	border: 2rpx solid #eee;
	border-radius: 8rpx;
	box-sizing: border-box;
}

/* 底部操作栏 */
.footer-bar {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	height: 100rpx;
	background: #fff;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 0 30rpx;
	box-shadow: 0 -4rpx 12rpx rgba(0, 0, 0, 0.06);
	.price-wrap {
		display: flex;
		align-items: baseline;
	}
	.total-label {
		font-size: 28rpx;
		color: #666;
	}
	.total-price {
		color: #ff6a00;
		font-size: 40rpx;
		font-weight: bold;
		margin-left: 16rpx;
	}
	.submit-btn {
		background: linear-gradient(90deg, #ff6a00, #ff3b00);
		color: #fff;
		border-radius: 50rpx;
	
		height: 72rpx;
		line-height: 72rpx;
		font-size: 32rpx;
		&::after {
			border: none;
		}
	}

}
.swiper-item{
	display: flex;
	width: 750rpx;
	height: 300rpx;
    justify-content: center;	
	
}
</style>
